# Generates Eclipse project (.project + .cproject) for all specified projects.
# Works only with fw4spl CMake script.
function(eclipseGenerator)
    foreach(PROJECT ${ARGV})
        message(STATUS "Generating ${PROJECT} Eclipse project")
        #configure eclipse project template 
        set(BUILD_PATH ${CMAKE_BINARY_DIR})
        set(PROJECT_NAME ${PROJECT})
        
        set(TYPE ${${PROJECT}_TYPE})
        if( TYPE STREQUAL "EXECUTABLE" )
            set(PROJECT_NAME_USER "exec-${PROJECT}")
        elseif( TYPE STREQUAL "LIBRARY" )
            set(PROJECT_NAME_USER "lib-${PROJECT}")
        elseif( TYPE STREQUAL "BUNDLE" )
            set(PROJECT_NAME_USER "bundle-${PROJECT}")
        elseif( TYPE STREQUAL "TEST" )
            set(PROJECT_NAME_USER "test-${PROJECT}")
        else()
            set(PROJECT_NAME_USER "unknown-${PROJECT}")
        endif()
        set(MAKE ${CMAKE_MAKE_PROGRAM})
        set(DEPS_INCLUDES "")
        get_target_property(PROJECT_INCLUDE_DIRECTORIES ${PROJECT} INCLUDE_DIRECTORIES)
        list(REMOVE_DUPLICATES PROJECT_INCLUDE_DIRECTORIES)
        foreach(DEPENDENCY ${PROJECT_INCLUDE_DIRECTORIES})
            set(DEPS_INCLUDES "${DEPS_INCLUDES}\n<listOptionValue builtIn=\"false\" value=\"${DEPENDENCY}\"/>")
        endforeach()
        if(WIN32)
            #add system include dirs
            SET(SYSTEM_INCLUDES "$ENV{INCLUDE}")
            foreach(SYS_INC ${SYSTEM_INCLUDES})
                string( REGEX REPLACE "\\\\" "/" SYS_INC ${SYS_INC} )
                set(DEPS_INCLUDES "${DEPS_INCLUDES}\n<listOptionValue builtIn=\"false\" value=\"${SYS_INC}\"/>")
            endforeach()
        endif()
        configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMake/eclipse/.cproject.in ${${PROJECT}_DIR}/.cproject [@ONLY] )
        configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMake/eclipse/.project.in ${${PROJECT}_DIR}/.project [@ONLY] )
    endforeach()
endfunction()
